using System;
using PPIDesktopClient.Logic;
using System.Collections.Generic;
using PPIDesktopClient.General;
using PPIDesktopClient.General;
using System.Text;

namespace PPIDesktopClient.Entities
{
    [Serializable]
    public class EUtility_Asset_XMissionStructures_Image : EBaseImage
    {
        private EUtility_Asset_XMissionStructure m_asset;
        private EUtility_Asset_XMissionStructures_Pole m_pole;

        public EUtility_Asset_XMissionStructure Asset
        {
            get
            {
                return m_asset;
            }
            set
            {
                m_asset = value;
            }
        }
        public EUtility_Asset_XMissionStructures_Pole Pole
        {
            get
            {
                return m_pole;
            }
            set
            {
                m_pole = value;
            }
        }
        

        #region Constructores
        #region summary
        /// <summary>
        /// Date: 04/28/2008
        /// Time: 14:25:56
        /// Generated by: VMCoder
        /// Generated using VirtualGenerator
        /// </summary>
        #endregion summary
        public EUtility_Asset_XMissionStructures_Image()
            : base()
        {
            m_pole = new EUtility_Asset_XMissionStructures_Pole();
            m_asset = new EUtility_Asset_XMissionStructure();
            if (m_key == "PRODUCTIVE_PPI")
            {
                m_ImageWebserviceFolder = Constants.K_DEVUTILITYFTPFOLDER;
                m_ImageWebFolder = Constants.K_DEVUTILITYFTPFOLDER;
            }
            else
            {
                m_ImageWebserviceFolder = Constants.K_BETAVENDORFTPFOLDER;
                m_ImageWebFolder = Constants.K_BETAVENDORWEBFOLDER;
            }
            m_ImageLocalFolder = Constants.K_ImageCachePath;
        }

        #region summary
        /// <summary>
        /// Date: 04/28/2008
        /// Time: 14:25:56
        /// Generated by: VMCoder
        /// Generated using VirtualGenerator
        /// </summary>
        #endregion summary
        public EUtility_Asset_XMissionStructures_Image(Int32 imageId)
            : this()
        {
            Id = imageId;

        }

        #region summary
        /// <summary>
        /// Date: 04/28/2008
        /// Time: 14:25:56
        /// Generated by: VMCoder
        /// Generated using VirtualGenerator
        /// </summary>
        #endregion summary
        public EUtility_Asset_XMissionStructures_Image(Int32 imageId, EUtility_Asset_XMissionStructure asset, double direction, double latitude, double longitude, double altitude, Int32 satelliteCount, DateTime satelliteTime, bool solutionAvailable, string filename, EUtility_Asset_XMissionStructures_Pole pole)
            : this(imageId)
        {
            Asset = asset;
            Direction = direction;
            Latitude = latitude;
            Longitude  = longitude;
            Altitude = altitude;
            SatelliteCount = satelliteCount;
            SatelliteTime = satelliteTime;
            SolutionAvailable = solutionAvailable;
            FileName = filename;
            Pole = pole;

        }

        #endregion Constructores

        #region Override Methods

        protected override int Insert()
        {
            return LUtility_Asset_XMissionStructure_Image.Insert(this);   
        }

        public override void Delete()
        {
            if (m_pole.Id != Int32.MinValue)
            {
                LUtility_Asset_XMissionStructure_Image.Disassociate(m_pole.Id);
            }
            else
            {
                LUtility_Asset_XMissionStructure_Image.Delete(Id);
                if (File.Exists)
                    File.Delete();
            }

            
        }

        public override void Associate(int poleId)
        {
            if(Id != Int32.MinValue)
                LUtility_Asset_XMissionStructure_Image.Associate(Id, poleId);
        }
        public override void Disassociate()
        {
            if (Id != Int32.MinValue)
                LUtility_Asset_XMissionStructure_Image.Disassociate(Id);
        }

        public override List<EBaseImage> GetServer(int offset)
        {
            List<EUtility_Asset_XMissionStructures_Image> _Images = LUtility_Asset_XMissionStructure_Image.GetAll(offset);
            List<EBaseImage> _BaseImages = new List<EBaseImage>();

            foreach (EUtility_Asset_XMissionStructures_Image i in _Images)
            {
                _BaseImages.Add(i);
            }
            return _BaseImages;           
        }

        public override EBaseAsset GetAsset()
        {
            return m_asset;
        }


        public override string GetHtml()
        {
            ConfigReader r = ConfigReader.GetInstance();
            string mode = r.GetConnectionType();
            StringBuilder s = new StringBuilder();

            string dirName = GetLocalPath().Directory.Name;
            string fileName = Asset.Id + "_" + Id;

            //Type=1&mode=DEV&dn=1500-1599&fn=1523_2266&w=50&h=50

            //s.AppendLine("<td><a href=\"http://www.dev-poleposition.com/Dev/WebSite/ImagePreview.aspx?mode=" + mode +"&Type=2&w=0&h=0&fn="+fileName+"&dn="+dirName+"\"><img src=\"http://www.dev-poleposition.com/Dev/WebSite/ImagePreview.aspx?mode=" + mode +"&Type=2&w="+Constants.k_PREVIEWIMAGEHEIGHT+"&h="+Constants.k_PREVIEWIMAGEHEIGHT+"&fn="+fileName+"&dn="+dirName+"\" border=\"0\"/></a></td>");
            s.AppendLine("<td><a href=\"#" + GetPlacemarkId() + ";balloon\"><img src=\"http://www.dev-poleposition.com/Dev/WebSite/ImagePreview.aspx?mode=" + mode + "&Type=2&w=" + Constants.k_PREVIEWIMAGEHEIGHT + "&h=" + Constants.k_PREVIEWIMAGEHEIGHT + "&fn=" + fileName + "&dn=" + dirName + "\" border=\"0\"/></a></td>");
            return s.ToString();
        }

        public override string GetHtmlDescription()
        {
            ConfigReader r = ConfigReader.GetInstance();
            string mode = r.GetConnectionType();
            string dirName = GetLocalPath().Directory.Name;
            string fileName = Asset.Id + "_" + Id;

            StringBuilder _Shtml = new StringBuilder();
            _Shtml.AppendLine("<table style='font-family:Verdana; font-size:10px;' border='0'>");
            _Shtml.AppendLine(" <tr>");
            _Shtml.AppendLine("     <td><a href=\"http://www.dev-poleposition.com/Dev/WebSite/ImagePreview.aspx?mode=" + mode + "&Type=2&w=0&h=0&fn=" + fileName + "&dn=" + dirName + "\" ><img src=\"http://www.dev-poleposition.com/Dev/WebSite/ImagePreview.aspx?mode=" + mode + "&Type=2&w=0&h=0&fn=" + fileName + "&dn=" + dirName + "\" ></a></td>");
            _Shtml.AppendLine(" </tr>");
            _Shtml.AppendLine("</table>");
            return _Shtml.ToString();
        }


        protected override string GetPlacemarkId()
        {
            return "UtilityImage_"+Id.ToString();
        }

        #endregion
    }
}

